<template>
	<view class="container">
		<view class="item" v-for="(item,index) in menuList" @click.stop="tabClcik(index)">
			<text class="name" :style="{color:currentTab==index?'#1296db':''}">{{item.name}}</text>
			<view class="icon-box" :class="currentTab==index?'icon-box-active':''">
				<u-icon size="16" name="arrow-down" :color="currentTab==index?'#1296db':'#5B5B6F'"></u-icon>
			</view>
			<view class="list" :style="{'max-height':currentTab==index?'400rpx':'0'}">
				<view class="list-item" v-for="(child,childIndex) in item.child" :key="childIndex"
					@click.stop="listClick(child,childIndex)">
					<text class="title" :style="{color:item.selectIndex==childIndex?'#1296db':''}">{{child}}</text>
					<u-icon name="checkmark" color="#2979ff" size="20" v-if="item.selectIndex==childIndex"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			filterData: {
				type: Array
			}
		},
		data() {
			return {
				menuList: [{
					name: '状态',
					selectIndex: 0,
					child: ['已完成', '未完成']
				}, {
					name: '分类',
					selectIndex: 0,
					child: [
						"门",
						"窗",
						"桌",
						"锁",
						"水",
						"电",
						"风扇",
						"下水道",
						"照明灯具",
						"开关",
						"厕所堵塞",
						"大修(洗手台)",
						"大修(地板)",
						"大修(天花板脱落)",
						"大修(漏水)",
					]
				}, ],
				currentTab: null,
				lastIndex: null,
				currentList: 0,
			}
		},
		methods: {
			click(item) {
				console.log('item', item);
			},
			tabClcik(index) {
				if (this.lastIndex == index && this.currentTab != null) {
					this.currentTab = null
					this.lastIndex = null
				} else {
					this.currentTab = index
					this.lastIndex = index
				}
			},
			listClick(item, index) {
				console.log(item)
				this.menuList[this.currentTab].selectIndex = index
				this.currentTab = null
			},
			//关闭下拉列表
			tabClose() {
				this.currentTab = null
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 40rpx 0;
		position: relative;

		.item {
			display: flex;
			align-items: center;

			&:last-child {
				margin-left: 40rpx;
			}

			.name {
				font-size: 32rpx;
				margin-right: 10rpx;
			}

			.icon-box {
				transition: 0.3s;
			}

			.icon-box-active {
				transform: rotate(180deg);
			}
		}

		.list {
			width: 100%;
			background-color: #fff;
			display: flex;
			flex-direction: column;
			position: absolute;
			left: 0;
			top: 118rpx;
			overflow: auto;

			.list-item {
				padding: 20rpx 40rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				border-bottom: 1px solid #ECECEC;
				font-size: 28rpx;
			}
		}
	}
</style>